//
//  BusinessShopflv.m
//  NewPro
//
//  Created by 何荧红 on 2018/12/24.
//  Copyright © 2018 何荧红. All rights reserved.
//

#import "BusinessShopflv.h"

@interface BusinessShopflv () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataArr;
@property (nonatomic, assign) CGFloat tabheight;

@end

@implementation BusinessShopflv

- (void)setLevelstr:(NSString *)levelstr{
    _levelstr = levelstr;
    NSInteger level = [_levelstr integerValue];
    if (level <= 5) {
        _dataArr = @[@"0.60%",@"0.61%",@"0.62%",@"0.63%",@"0.64%",@"0.65%"];
    }else if (level >= 6){
        _dataArr = @[@"0.55%",@"0.56%",@"0.57%",@"0.58%",@"0.59%",@"0.60%",@"0.61%",@"0.62%",@"0.63%",@"0.64%",@"0.65%"];
    }
    _tabheight = 40 * _dataArr.count;
    [_tableView reloadData];
}

- (NSArray *)dataArr{
    if (!_dataArr) {
        _dataArr = @[@"0.55%",@"0.56%",@"0.57%",@"0.58%",@"0.59%",@"0.60%",@"0.61%",@"0.62%",@"0.63%",@"0.64%",@"0.65%"];
        _tabheight = 40 * _dataArr.count;
    }
    return _dataArr;
}

- (instancetype)init{
    self = [super init];
    if (self) {
        self.frame = CGRectMake(0, SCREEN_HEIGHT * 2, SCREEN_WIDTH, SCREEN_HEIGHT);
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
        [self CleanWithView];
    }
    return self;
}
- (void)CleanWithView{
    _tabheight = 440;
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, _tabheight) style:UITableViewStylePlain];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell23"];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self addSubview:self.tableView];
}
- (void)ViewDidPush{
    self.hidden = NO;
    self.frame = CGRectMake(0, -iPhoneX_Top, SCREEN_WIDTH, SCREEN_HEIGHT);
    [UIView animateWithDuration:0.3 animations:^{
        self.tableView.frame = CGRectMake(0, SCREEN_HEIGHT - self.tabheight, SCREEN_WIDTH, self.tabheight);
    }];
}
- (void)ViewDidPull{
    self.hidden = YES;
    self.frame = CGRectMake(0, SCREEN_HEIGHT * 2, SCREEN_WIDTH, SCREEN_HEIGHT);
    [UIView animateWithDuration:0.3 animations:^{
        self.tableView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, self.tabheight);
    }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell23"];
    for (UIView *view in cell.contentView.subviews) {
        [view removeFromSuperview];
    }
    UILabel *subtitle = [[UILabel alloc]init];
    subtitle.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:16];
    subtitle.textColor = [UIColor colorWithHexString:@"333333"];
    subtitle.textAlignment = NSTextAlignmentCenter;
    if (self.dataArr.count > 0) {
        subtitle.text = self.dataArr[indexPath.section];
    }
    [cell.contentView addSubview:subtitle];
    [subtitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(cell.contentView.mas_left).offset(14);
        make.centerY.equalTo(cell.contentView.mas_centerY);
        make.right.equalTo(cell.contentView.mas_right).offset(-14);
    }];
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = [UIColor colorWithHexString:@"f5f5f5"];
    [cell.contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1);
        make.left.equalTo(cell.contentView.mas_left).offset(14);
        make.right.equalTo(cell.contentView.mas_right).offset(-14);
        make.bottom.equalTo(cell.contentView.mas_bottom).offset(-1);
    }];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self ViewDidPull];
    if (self.GetWithFlvBlock) self.GetWithFlvBlock(self.dataArr[indexPath.section]);
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self ViewDidPull];
}


@end
